package com.quanxiaoha.ai.robot.config;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.ChatMemoryRepository;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.chat.memory.repository.cassandra.CassandraChatMemoryRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Caius
 * @description
 * @since Created in 2025-09-04
 */
@Configuration
public class ChatMemoryConfig {

    /**
     * 记忆存储
     */
    @Resource
    private CassandraChatMemoryRepository chatMemoryRepository;

    /**
     * chatMemory 初始化
     * @return
     */
    @Bean
    public ChatMemory chatMemory() {
        return MessageWindowChatMemory.builder()
                .maxMessages(50)  // 最大窗口为 50 默认是 20
                .chatMemoryRepository(chatMemoryRepository) // 记忆存储
                .build();
    }
}
